home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Dreamweaver 3 / Configuration / Behaviors / Actions / Drag Layer.js < prev    next >
Encoding:
Text File  |  1999-12-01  |  25.2 KB  |  671 lines

  1. // Copyright 1998 Macromedia, Inc. All rights reserved.
  2.  
  3. //*************** GLOBAL VARS  *****************
  4.  
  5. var helpDoc = MM.HELP_behDragLayer;
  6.  
  7. function initGlobals() {
  8.   //Initial Form Values
  9.   GlayerMenu = 0;
  10.   GconstrainMenu = 0;
  11.   GconstrainUp = "";
  12.   GconstrainDown = "";
  13.   GconstrainLeft = "";
  14.   GconstrainRight = "";
  15.   GtargetLeft = "";
  16.   GtargetTop = "";
  17.   GtargetTolerance = "";
  18.  
  19.   GhandleMenu = 0;
  20.   GhandleLeft = "";
  21.   GhandleTop = "";
  22.   GhandleWidth = "";
  23.   GhandleHeight = "";
  24.   GbringToFront = true;
  25.   GdropBackMenu = 0;
  26.   GdragJavascript = "";
  27.   GdropJavascript = "";
  28.   GcallJsWhenSnapped = true;
  29. }
  30.  
  31. var T;
  32. var GlayerMenu;
  33. var GconstrainMenu;
  34. var GconstrainUp;
  35. var GconstrainDown;
  36. var GconstrainLeft;
  37. var GconstrainRight;
  38. var GtargetLeft;
  39. var GtargetTop;
  40. var GtargetTolerance;
  41. var GhandleMenu;
  42. var GhandleLeft;
  43. var GhandleTop;
  44. var GhandleWidth;
  45. var GhandleHeight;
  46. var GbringToFront;
  47. var GdropBackMenu;
  48. var GdragJavascript;
  49. var GdropJavascript;
  50. var GcallJsWhenSnapped;
  51.  
  52. //******************* BEHAVIOR FUNCTION **********************
  53.  
  54. //Lets you drag a layer, snap it to a location, and call a JavaScript.
  55. //Accepts the following args:
  56. //  objName  - simple object name, or layer object ref for Netscape (ex: document.layers['foo'])
  57. //  x        - ignored (there for backward compatibility)
  58. //  hL, hT   - integers, define top-left corner of drag handle area within layer
  59. //  hW, hH   - positive integers, define width and height of drag handle area
  60. //             For example, to define a title-bar drag handle, use hL=0, hT=0, hW=100, hH=30
  61. //  toFront  - boolean, if true layer becomes topmost layer while dragged
  62. //  dropBack - boolean, (used only if toFront is true)
  63. //             if true, the layer will return to its original zIndex position when dropped
  64. //             if false, the layer will remain on top when dropped
  65. //  cU       - positive integer, distance layer can be dragged up from its original position
  66. //  cD       - positive integer, distance layer can be dragged down from its original position
  67. //  cL       - positive integer, distance layer can be dragged left from its original position
  68. //  cR       - positive integer, distance layer can be dragged right from its original position
  69. //  targL    - integer, absolute X location (from top/left corner of window) to snap to
  70. //  targT    - integer, absolute Y location (from top/left corner of window) to snap to
  71. //  tol      - tolerance, pixel-distance from target layer can be and still snap to target
  72. //  dropJS   - JavaScript to execute when snapped (can be blank, but use empty quotes "")
  73. //  et       - boolean "every time". if true, calls dropJS every time
  74. //                                   if false, only calls dropJS if snapped to target
  75. //  dragJS   - JavaScript to execute while dragging (can be blank, but use empty quotes "")
  76. //
  77. //This function requires layers and only works for 4.0 browsers. It is a composite of 4
  78. //functions, handling initialization, and events mousedown, mousemove, and mouseup.
  79. //Fails gracefully on older browsers by ensuring the .layers or .all arrays exist.
  80.  
  81. function MM_dragLayer(objName,x,hL,hT,hW,hH,toFront,dropBack,cU,cD,cL,cR,targL,targT,tol,dropJS,et,dragJS) { //v3.0
  82.   //Copyright 1998 Macromedia, Inc. All rights reserved.
  83.   var i,j,aLayer,retVal,curDrag=null,NS=(navigator.appName=='Netscape'), curLeft, curTop;
  84.   if (!document.all && !document.layers) return false;
  85.   retVal = true; if(!NS && event) event.returnValue = true;
  86.   if (MM_dragLayer.arguments.length > 1) {
  87.     curDrag = MM_findObj(objName); if (!curDrag) return false;
  88.     if (!document.allLayers) { document.allLayers = new Array();
  89.       with (document) if (NS) { for (i=0; i<layers.length; i++) allLayers[i]=layers[i];
  90.         for (i=0; i<allLayers.length; i++) if (allLayers[i].document && allLayers[i].document.layers)
  91.           with (allLayers[i].document) for (j=0; j<layers.length; j++) allLayers[allLayers.length]=layers[j];
  92.       } else for (i=0;i<all.length;i++) if (all[i].style&&all[i].style.position) allLayers[allLayers.length]=all[i];}
  93.     curDrag.MM_dragOk=true; curDrag.MM_targL=targL; curDrag.MM_targT=targT;
  94.     curDrag.MM_tol=Math.pow(tol,2); curDrag.MM_hLeft=hL; curDrag.MM_hTop=hT;
  95.     curDrag.MM_hWidth=hW; curDrag.MM_hHeight=hH; curDrag.MM_toFront=toFront;
  96.     curDrag.MM_dropBack=dropBack; curDrag.MM_dropJS=dropJS;
  97.     curDrag.MM_everyTime=et; curDrag.MM_dragJS=dragJS;
  98.     curDrag.MM_oldZ = (NS)?curDrag.zIndex:curDrag.style.zIndex;
  99.     curLeft= (NS)?curDrag.left:curDrag.style.pixelLeft; curDrag.MM_startL = curLeft;
  100.     curTop = (NS)?curDrag.top:curDrag.style.pixelTop; curDrag.MM_startT = curTop;
  101.     curDrag.MM_bL=(cL<0)?null:curLeft-cL; curDrag.MM_bT=(cU<0)?null:curTop -cU;
  102.     curDrag.MM_bR=(cR<0)?null:curLeft+cR; curDrag.MM_bB=(cD<0)?null:curTop +cD;
  103.     curDrag.MM_LEFTRIGHT=0; curDrag.MM_UPDOWN=0; curDrag.MM_SNAPPED=false; //use in your JS!
  104.     document.onmousedown = MM_dragLayer; document.onmouseup = MM_dragLayer;
  105.     if (NS) document.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  106.   } else {
  107.     var theEvent = ((NS)?objName.type:event.type);
  108.     if (theEvent == 'mousedown') {
  109.       var mouseX = (NS)?objName.pageX : event.clientX + document.body.scrollLeft;
  110.       var mouseY = (NS)?objName.pageY : event.clientY + document.body.scrollTop;
  111.       var maxDragZ=null; document.MM_maxZ = 0;
  112.       for (i=0; i<document.allLayers.length; i++) { aLayer = document.allLayers[i];
  113.         var aLayerZ = (NS)?aLayer.zIndex:aLayer.style.zIndex;
  114.         if (aLayerZ > document.MM_maxZ) document.MM_maxZ = aLayerZ;
  115.         var isVisible = (((NS)?aLayer.visibility:aLayer.style.visibility).indexOf('hid') == -1);
  116.         if (aLayer.MM_dragOk != null && isVisible) with (aLayer) {
  117.           var parentL=0; var parentT=0;
  118.           if (!NS) { parentLayer = aLayer.parentElement;
  119.             while (parentLayer != null && parentLayer.style.position) {
  120.               parentL += parentLayer.offsetLeft; parentT += parentLayer.offsetTop;
  121.               parentLayer = parentLayer.parentElement; } }
  122.           var tmpX=mouseX-(((NS)?pageX:style.pixelLeft+parentL)+MM_hLeft);
  123.           var tmpY=mouseY-(((NS)?pageY:style.pixelTop +parentT)+MM_hTop);
  124.           var tmpW = MM_hWidth;  if (tmpW <= 0) tmpW += ((NS)?clip.width :offsetWidth);
  125.           var tmpH = MM_hHeight; if (tmpH <= 0) tmpH += ((NS)?clip.height:offsetHeight);
  126.           if ((0 <= tmpX && tmpX < tmpW && 0 <= tmpY && tmpY < tmpH) && (maxDragZ == null
  127.               || maxDragZ <= aLayerZ)) { curDrag = aLayer; maxDragZ = aLayerZ; } } }
  128.       if (curDrag) {
  129.         document.onmousemove = MM_dragLayer; if (NS) document.captureEvents(Event.MOUSEMOVE);
  130.         curLeft = (NS)?curDrag.left:curDrag.style.pixelLeft;
  131.         curTop = (NS)?curDrag.top:curDrag.style.pixelTop;
  132.         MM_oldX = mouseX - curLeft; MM_oldY = mouseY - curTop;
  133.         document.MM_curDrag = curDrag;  curDrag.MM_SNAPPED=false;
  134.         if(curDrag.MM_toFront) {
  135.           eval('curDrag.'+((NS)?'':'style.')+'zIndex=document.MM_maxZ+1');
  136.           if (!curDrag.MM_dropBack) document.MM_maxZ++; }
  137.         retVal = false; if(!NS) event.returnValue = false;
  138.     } } else if (theEvent == 'mousemove') {
  139.       if (document.MM_curDrag) with (document.MM_curDrag) {
  140.         var mouseX = (NS)?objName.pageX : event.clientX + document.body.scrollLeft;
  141.         var mouseY = (NS)?objName.pageY : event.clientY + document.body.scrollTop;
  142.         newLeft = mouseX-MM_oldX; newTop  = mouseY-MM_oldY;
  143.         if (MM_bL!=null) newLeft = Math.max(newLeft,MM_bL);
  144.         if (MM_bR!=null) newLeft = Math.min(newLeft,MM_bR);
  145.         if (MM_bT!=null) newTop  = Math.max(newTop ,MM_bT);
  146.         if (MM_bB!=null) newTop  = Math.min(newTop ,MM_bB);
  147.         MM_LEFTRIGHT = newLeft-MM_startL; MM_UPDOWN = newTop-MM_startT;
  148.         if (NS) {left = newLeft; top = newTop;}
  149.         else {style.pixelLeft = newLeft; style.pixelTop = newTop;}
  150.         if (MM_dragJS) eval(MM_dragJS);
  151.         retVal = false; if(!NS) event.returnValue = false;
  152.     } } else if (theEvent == 'mouseup') {
  153.       document.onmousemove = null;
  154.       if (NS) document.releaseEvents(Event.MOUSEMOVE);
  155.       if (NS) document.captureEvents(Event.MOUSEDOWN); //for mac NS
  156.       if (document.MM_curDrag) with (document.MM_curDrag) {
  157.         if (typeof MM_targL =='number' && typeof MM_targT == 'number' &&
  158.             (Math.pow(MM_targL-((NS)?left:style.pixelLeft),2)+
  159.              Math.pow(MM_targT-((NS)?top:style.pixelTop),2))<=MM_tol) {
  160.           if (NS) {left = MM_targL; top = MM_targT;}
  161.           else {style.pixelLeft = MM_targL; style.pixelTop = MM_targT;}
  162.           MM_SNAPPED = true; MM_LEFTRIGHT = MM_startL-MM_targL; MM_UPDOWN = MM_startT-MM_targT; }
  163.         if (MM_everyTime || MM_SNAPPED) eval(MM_dropJS);
  164.         if(MM_dropBack) {if (NS) zIndex = MM_oldZ; else style.zIndex = MM_oldZ;}
  165.         retVal = false; if(!NS) event.returnValue = false; }
  166.       document.MM_curDrag = null;
  167.     }
  168.     if (NS) document.routeEvent(objName);
  169.   } return retVal;
  170. }
  171.  
  172. document.VERSION_MM_dragLayer = 3.0; //define latest version number for behavior inspector
  173.  
  174. //******************* API **********************
  175.  
  176. //Checks for the existence of layers.
  177. //If none exist, returns false so this Action is grayed out.
  178.  
  179. function canAcceptBehavior(theTag,theEvent) {
  180.   var nameArray = dw.getObjectRefs("NS 4.0","document","LAYER");  //get layer names (includes CSS)
  181.   return (nameArray.length > 0);
  182. }
  183.  
  184.  
  185.  
  186. //Returns a Javascript function to be inserted in HTML head with script tags.
  187.  
  188. function behaviorFunction(){
  189.   return "MM_findObj,MM_dragLayer";
  190. }
  191.  
  192.  
  193.  
  194. //Returns fn call to insert in HTML tag <TAG... onEvent='thisFn(arg)'>
  195.  
  196. function applyBehavior() {
  197.   var objNS,hL,hT,hW,hH,toFront,dropBack,cU,cD,cL,cR,targL,targT,tol,dropJS,et,dragJS;
  198.  
  199.   var index, errMsg="", argList="";
  200.  
  201.   if (findObject("mainLayer").visibility != 'hidden') {
  202.     getMain();
  203.   } else {
  204.     getOptions();
  205.   }
  206.   //get layer obj
  207.   index = GlayerMenu;
  208.   objNS = document.MM_NS_REFS[index]; //get layer name from list
  209.   if (objNS.indexOf(REF_UNNAMED) == 0) errMsg += "\n"+MSG_UnnamedLayer;
  210.   argList += "'"+getNameFromRef(objNS)+"','',";
  211.  
  212.   //get drag handle
  213.   if (GhandleMenu == 0) {
  214.     hL=0; hT=0; hW=0; hH=0;
  215.   } else {
  216.     hL = GhandleLeft;   if (!hL) hL = 0; //if empty, use zero
  217.     hT = GhandleTop;    if (!hT) hT = 0;
  218.     hW = GhandleWidth;  if (!hW) hW = 0;
  219.     hH = GhandleHeight; if (!hH) hH = 0;
  220.     if ((hL != ""+(parseInt(hL))) ||  //if not a number
  221.         (hT != ""+(parseInt(hT))) ||
  222.         (hW != ""+(parseInt(hW))) ||
  223.         (hH != ""+(parseInt(hH)))) errMsg += "\n"+MSG_HandleNotInts;
  224.   }
  225.   argList += hL + "," + hT + "," + hW + "," + hH + ",";
  226.  
  227.   //get while-dragging setting
  228.   toFront = GbringToFront;
  229.   index = GdropBackMenu;
  230.   dropBack = (index == 1);
  231.   argList += toFront + "," + dropBack + ",";
  232.  
  233.   //get constraints
  234.   if (GconstrainMenu == 0) {
  235.     cU=-1; cD=-1; cL=-1; cR=-1;
  236.   } else {
  237.     cU = GconstrainUp;
  238.     cD = GconstrainDown;
  239.     cL = GconstrainLeft;
  240.     cR = GconstrainRight;
  241.     if ((cU && cU != ""+(parseInt(cU))) ||  //if not a number
  242.         (cD && cD != ""+(parseInt(cD))) ||
  243.         (cL && cL != ""+(parseInt(cL))) ||
  244.         (cR && cR != ""+(parseInt(cR)))) errMsg += "\n"+MSG_ConstraintsNotInts;
  245.     if ((cU == ""+(parseInt(cU)) && cU < 0) ||  //if number, but negative
  246.         (cD == ""+(parseInt(cD)) && cD < 0) ||
  247.         (cL == ""+(parseInt(cL)) && cL < 0) ||
  248.         (cR == ""+(parseInt(cR)) && cR < 0)) errMsg += "\n"+MSG_ConstraintsNotPos;
  249.   }
  250.   if (!cU) cU = -1;
  251.   if (!cD) cD = -1;
  252.   if (!cL) cL = -1;
  253.   if (!cR) cR = -1;
  254.   argList += cU + "," + cD + "," + cL + "," + cR + ",";
  255.  
  256.   //get target location and tolerance
  257.   targL = GtargetLeft;
  258.   targT = GtargetTop;
  259.   tol   = GtargetTolerance;
  260.   if ((targL && targL != ""+(parseInt(targL))) ||   //if not empty, and not number
  261.       (targT && targT != ""+(parseInt(targT))) ||
  262.       (tol   && tol   != ""+(parseInt(tol)))) errMsg += "\n"+MSG_TargetNotInts;
  263.   if (tol && tol == ""+(parseInt(tol)) && tol < 0) errMsg += "\n"+MSG_TolNotPositive;
  264.   targL = (targL)?targL:false; //if its empty, use false
  265.   targT = (targT)?targT:false;
  266.   tol   = (tol  )?tol  :0; //if empty, use zero
  267.   argList += targL + "," + targT + "," + tol + ",";
  268.  
  269.   //get javascript
  270.   dropJS = escQuotes(GdropJavascript);
  271.   et = !GcallJsWhenSnapped;
  272.   dragJS = escQuotes(GdragJavascript);
  273.   argList += "'" + dropJS + "'," + et + ",'" + dragJS + "'";
  274.  
  275.   if (errMsg) return errMsg
  276.   else {
  277.     updateBehaviorFns("MM_findObj","MM_dragLayer");
  278.     return "MM_dragLayer("+argList+")";  //return fn call with args
  279.   }
  280. }
  281.  
  282.  
  283.  
  284. //Returns a dummy function call to inform Dreamweaver the type of certain behavior
  285. //call arguments. This information is used by DW to fixup behavior args when the
  286. //document is moved or changed.
  287. //
  288. //It is passed an actual function call string generated by applyBehavior(), which
  289. //may have a variable list of arguments, and this should return a matching mask.
  290. //
  291. //The return values are:
  292. //  URL     : argument could be a file path, which DW will update during Save As...
  293. //  NS4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
  294. //  IE4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
  295. //  other...: argument is ignored
  296.  
  297. function identifyBehaviorArguments(fnCallStr) {
  298.   var argArray, argList="";
  299.  
  300.   argArray = extractArgs(fnCallStr);
  301.   if (argArray.length > 2) {
  302.     argList += (argArray[1].indexOf(".")==-1)? "objName,other" : "NS4.0ref,IE4.0ref";
  303.     for (i=0; i<argArray.length-3; i++) argList += ",other";
  304.   }
  305.   return argList;
  306. }
  307.  
  308.  
  309.  
  310. //Given the original function call, this parses out the args and updates
  311. //the UI. All values are written to a set of globals, then some are written
  312. //to the displayed form.
  313.  
  314. function inspectBehavior(fnStr){
  315.   var argArray,found,numLayers,i;
  316.   var objNS,objIE,hL,hT,hW,hH,toFront,dropBack,cU,cD,cL,cR,targL,targT,tol,dropJS;
  317.  
  318.   argArray = extractArgs(fnStr);//get new list of layer,vis pairs
  319.   if (argArray.length > 16) { //function call + 16 args
  320.  
  321.     //set layer obj
  322.     objNS=unescQuotes(argArray[1]);
  323.     objIE=unescQuotes(argArray[2]);
  324.     found = false;
  325.     numLayers = document.MM_NS_REFS.length;
  326.     for (i=0; i<numLayers; i++){  //check if layer is in menu
  327.       if ((objNS && ((objNS == document.MM_NS_REFS[i]) || (objNS == getNameFromRef(document.MM_NS_REFS[i])))) ||
  328.           (objIE && objIE == document.MM_IE_REFS[i]) ) { //if layer there
  329.         GlayerMenu = i;
  330.         found = true;
  331.         break;
  332.       }
  333.     }
  334.     if (!found) alert(errMsg(MSG_LayerNotFound,objNS));
  335.  
  336.     //set drag handle
  337.     hL = argArray[3];
  338.     hT = argArray[4];
  339.     hW = argArray[5];
  340.     hH = argArray[6];
  341.     if (hL==0 && hT==0 && hW==0 && hH==0) {
  342.       GhandleMenu = 0;
  343.     } else {
  344.       GhandleMenu   = 1;
  345.       GhandleLeft   = (hL==0)?"":hL;
  346.       GhandleTop    = (hT==0)?"":hT;
  347.       GhandleWidth  = (hW==0)?"":hW;
  348.       GhandleHeight = (hH==0)?"":hH;
  349.     }
  350.  
  351.     //set while-dragging settings
  352.     GbringToFront = (argArray[7]=='true')?true:false;
  353.     GdropBackMenu = (argArray[8]=='true')?1:0;
  354.  
  355.     //set constraints
  356.     cU = argArray[9];
  357.     cD = argArray[10];
  358.     cL = argArray[11];
  359.     cR = argArray[12];
  360.     if (cU == -1 && cD == -1 && cL == -1 && cD == -1) {
  361.       GconstrainMenu = 0;
  362.     } else {
  363.       GconstrainMenu = 1;
  364.       if (cU != -1) GconstrainUp    = cU;
  365.       if (cD != -1) GconstrainDown  = cD;
  366.       if (cL != -1) GconstrainLeft  = cL;
  367.       if (cR != -1) GconstrainRight = cR;
  368.     }
  369.  
  370.     //set target location and tolerance
  371.     GtargetLeft = (argArray[13]=="false")?"":argArray[13];
  372.     GtargetTop  = (argArray[14]=="false")?"":argArray[14];
  373.     GtargetTolerance = (argArray[15]==0)?"":argArray[15];
  374.  
  375.     //set javascript
  376.     GdropJavascript = argArray[16];
  377.     if (argArray.length > 17) //function call + 17 args
  378.       GcallJsWhenSnapped = !eval(argArray[17]);
  379.     if (argArray.length > 18) //function call + 18 args
  380.       GdragJavascript = argArray[18];
  381.  
  382.     setMain();
  383.   }
  384. }
  385.  
  386.  
  387.  
  388. //***************** LOCAL FUNCTIONS  ******************
  389.  
  390.  
  391. //Detects if the onmousedown event is selected, which makes it invalid to proceed.
  392. //Searches for the layer surround the current selection. If match is found,
  393. //displays and loads the main form with all the layer "nice names", and selects
  394. //the current one. If anything fails, it displays the error layer.
  395.  
  396. function initializeUI(){
  397.   initGlobals();
  398.   var nsRefs,ieRefs,tags,niceNameSrcArray,nameArray,i,j,tagTokenArray,numLayers;
  399.  
  400.   document.MM_NS_REFS = new Array();
  401.   document.MM_IE_REFS = new Array();
  402.   document.MM_TAGS    = new Array();
  403.   nsRefs = getObjectRefs("NS 4.0","document","LAYER"); //store parallel NS refs
  404.   ieRefs = getObjectRefs("IE 4.0","document","LAYER"); //store parallel IE refs
  405.   tags   = getObjectTags("document","LAYER"); //store parallel tags
  406.  
  407.   //remove ILAYERs if any while copying all refs into global arrays
  408.   j = 0;
  409.   for (i=0; i<tags.length; i++) {
  410.     tagTokenArray = getTokens(tags[i],"< ");
  411.     if (tagTokenArray[0].toUpperCase()!="ILAYER") { //if layer's not an ILAYER
  412.       document.MM_NS_REFS[j] = nsRefs[i];
  413.       document.MM_IE_REFS[j] = ieRefs[i];
  414.       document.MM_TAGS[j++]  = tags[i];
  415.     }
  416.   }
  417.  
  418.   //Search for unreferenceable objects. <DIV id="foo"> is IE only, <LAYER> is NS only.
  419.   //if REF_CANNOT found, return empty string, and use IE refs for nice namelist.
  420.   niceNameSrcArray = document.MM_NS_REFS;
  421.   for (i=0; i<document.MM_NS_REFS.length; i++) {
  422.     if (document.MM_IE_REFS[i].indexOf(REF_CANNOT) == 0) {
  423.       document.MM_IE_REFS[i] = ""; //blank it out
  424.     }
  425.     if (document.MM_NS_REFS[i].indexOf(REF_CANNOT) == 0) {
  426.       document.MM_NS_REFS[i] = ""; //blank it out
  427.       niceNameSrcArray = document.MM_IE_REFS; //use the IE list
  428.     }
  429.   }
  430.   nameArray = niceNames(niceNameSrcArray,TYPE_Layer);  //get layer names (includes CSS)
  431.  
  432.   with (findObject("layerMenu")) {
  433.     for (i=0; i<nameArray.length; i++) options[i]=new Option(nameArray[i]); //load menu
  434.     selectedIndex = 0;
  435.   }
  436.  
  437.   //Initialize the TabControl.  (Pass in the prefix used for the tab layers)
  438.   T = new TabControl('Tab');
  439.   //Add tab pages.   (Pass the layer name, and the page object)
  440.   T.addPage('mainLayer', new Pg1(LABEL_Basic));
  441.   T.addPage('optionsLayer', new Pg2(LABEL_Advanced));
  442.   //Initialize and display the tabs.  (Could pass the name of a page to start on)
  443.   T.start();
  444. }
  445.  
  446.  
  447.  
  448. //Scan the tag for the selected layer to get it's current left,top position
  449. //Put these position values into the form
  450.  
  451. function getLayerPosition() {
  452.   var index,layerTag,layerTokens,i,topVal='',leftVal='';
  453.  
  454.     index = findObject("layerMenu").selectedIndex;
  455.     layerTag = document.MM_TAGS[index].toLowerCase(); //get layer tag from list
  456.     if (layerTag) {
  457.  
  458.       //search layer tag for 'left' and 'top' attributes
  459.       layerTokens = dreamweaver.getTokens(layerTag,"=;:\"\' ");
  460.       for (i=0; i<(layerTokens.length-1); i++) {  //search for 'left' value
  461.         if (layerTokens[i] == "left") {
  462.           leftVal = layerTokens[i+1];
  463.           break;
  464.       } }
  465.       for (i=0; i<(layerTokens.length-1); i++) {  //search for 'top' value
  466.         if (layerTokens[i] == "top") {
  467.           topVal = layerTokens[i+1];
  468.           break;
  469.       } }
  470.  
  471.       //if followed by "px", strip off
  472.       if (leftVal.substring(leftVal.length-2,leftVal.length)=="px")
  473.         leftVal = leftVal.substring(0,leftVal.length-2); //remove px if there
  474.       if (topVal.substring(topVal.length-2,topVal.length)=="px")
  475.         topVal = topVal.substring(0,topVal.length-2); //remove px if there
  476.  
  477.       //if valid integers, insert in form
  478.       if (leftVal == ""+parseInt(leftVal) && topVal == ""+parseInt(topVal)) {
  479.         findObject("targetLeft").value = leftVal;
  480.         findObject("targetTop").value = topVal;
  481.         //add default tolerance if nothing there
  482.         with (findObject("targetTolerance")) if (!value) value = 50;
  483.       } else {
  484.         alert(MSG_LayerHasNoPosn);
  485.       }
  486.     }
  487. }
  488.  
  489.  
  490. function getMain() {
  491.   GlayerMenu       = findObject("layerMenu").selectedIndex;
  492.   GconstrainMenu   = findObject("constrainMenu").selectedIndex;
  493.   GconstrainUp     = findObject("constrainUp").value;
  494.   GconstrainDown   = findObject("constrainDown").value;
  495.   GconstrainLeft   = findObject("constrainLeft").value;
  496.   GconstrainRight  = findObject("constrainRight").value;
  497.   GtargetLeft      = findObject("targetLeft").value;
  498.   GtargetTop       = findObject("targetTop").value;
  499.   GtargetTolerance = findObject("targetTolerance").value;
  500. }
  501. function setMain() {
  502.  findObject("layerMenu").selectedIndex     = GlayerMenu;
  503.  findObject("constrainMenu").selectedIndex = GconstrainMenu;
  504.  T.update("constrainMenu"); //call update class to show or hide constrain fields
  505.  findObject("constrainUp").value           = GconstrainUp;
  506.  findObject("constrainDown").value         = GconstrainDown;
  507.  findObject("constrainLeft").value         = GconstrainLeft;
  508.  findObject("constrainRight").value        = GconstrainRight;
  509.  findObject("targetLeft").value            = GtargetLeft;
  510.  findObject("targetTop").value             = GtargetTop;
  511.  findObject("targetTolerance").value       = GtargetTolerance;
  512. }
  513. function getOptions() {
  514.   GhandleMenu      = findObject("handleMenu").selectedIndex;
  515.   GhandleLeft      = findObject("handleLeft").value;
  516.   GhandleTop       = findObject("handleTop").value;
  517.   GhandleWidth     = findObject("handleWidth").value;
  518.   GhandleHeight    = findObject("handleHeight").value;
  519.   GbringToFront    = findObject("bringToFront").checked;
  520.   GdropBackMenu    = findObject("dropBackMenu").selectedIndex;
  521.   GdragJavascript  = findObject("dragJavascript").value;
  522.   GdropJavascript  = findObject("dropJavascript").value;
  523.   GcallJsWhenSnapped = findObject("callJsWhenSnapped").checked;
  524. }
  525. function setOptions() {
  526.  findObject("handleMenu").selectedIndex   = GhandleMenu;
  527.  findObject("handleLeft").value           = GhandleLeft;
  528.  findObject("handleTop").value            = GhandleTop;
  529.  findObject("handleWidth").value          = GhandleWidth;
  530.  findObject("handleHeight").value         = GhandleHeight;
  531.  findObject("bringToFront").checked       = GbringToFront;
  532.  findObject("dropBackMenu").selectedIndex = GdropBackMenu;
  533.  findObject("dragJavascript").value       = GdragJavascript;
  534.  findObject("dropJavascript").value       = GdropJavascript;
  535.  findObject("callJsWhenSnapped").checked  = GcallJsWhenSnapped;
  536. }
  537.  
  538. //*************** Pg1 Class ********************
  539.  
  540. function Pg1(theTabLabel) {
  541.   this.tabLabel = theTabLabel;
  542.   this.constrainSetObj = findObject("constrainSet");
  543.   this.constrainSetHTML = stripSpaces(this.constrainSetObj.innerHTML);
  544.   this.myLayer = findObject("mainLayer");  //used for rendering bug workaround
  545. }
  546. Pg1.prototype.getTabLabel = Pg1_getTabLabel;
  547. Pg1.prototype.canLoad = Pg1_canLoad;
  548. Pg1.prototype.load = Pg1_load;
  549. Pg1.prototype.update = Pg1_update;
  550. Pg1.prototype.unload = Pg1_unload;
  551. Pg1.prototype.lastUnload = Pg1_lastUnload;
  552.  
  553. function Pg1_getTabLabel() {
  554.   return this.tabLabel;
  555. }
  556.  
  557. //Called to check if a page can be loaded
  558. //
  559. function Pg1_canLoad() {
  560.   with (this) {
  561.     constrainSetObj.innerHTML = (GconstrainMenu)?constrainSetHTML:"";
  562.   }
  563.   return true;
  564. }
  565.  
  566. //Called when the layer for this page is displayed.
  567. // Use this call to initialize controls.
  568. //
  569. function Pg1_load() {
  570.   setMain();
  571. }
  572.  
  573. //Called when one of the page controls calls the tabControl update function.
  574. // Use this call to respond to user input.
  575. //
  576. function Pg1_update(theItemName) {
  577.   var theObj, temp, temp2;
  578.  
  579.   theObj = findObject(theItemName);
  580.   with (this) {
  581.     if (theItemName == "constrainMenu") {
  582.       myLayer.visibility = "hidden";  //workaround: hide layer before changing
  583.       constrainSetObj.innerHTML = (theObj.selectedIndex)?constrainSetHTML:"";
  584.       myLayer.visibility = "visible";
  585.   } }
  586. }
  587.  
  588. //Called when another page is about to be shown, or finish() is called on
  589. // the tabControl.  Use this call to perform any finishing tasks.
  590. //
  591. function Pg1_unload() {
  592.   getMain();
  593.   //setOptions();
  594.   return true;
  595. }
  596.  
  597. //Called when finish() is called on the tabControl.
  598. // Use this call to perform any last minute page updates.
  599. //
  600. function Pg1_lastUnload() {
  601.   //alert("lastUnload() called " + this.tabLabel);
  602.   return true;
  603. }
  604.  
  605.  
  606. //********** Pg2 Class *************
  607. function Pg2(theTabLabel) {
  608.   this.tabLabel = theTabLabel;
  609.   this.handleSetObj = findObject("handleSet");
  610.   this.handleSetHTML = stripSpaces(this.handleSetObj.innerHTML);
  611.   this.myLayer = findObject("optionsLayer");  //used for rendering bug workaround
  612. }
  613. Pg2.prototype.getTabLabel = Pg2_getTabLabel;
  614. Pg2.prototype.canLoad = Pg2_canLoad;
  615. Pg2.prototype.load = Pg2_load;
  616. Pg2.prototype.update = Pg2_update;
  617. Pg2.prototype.unload = Pg2_unload;
  618. Pg2.prototype.lastUnload = Pg2_lastUnload;
  619.  
  620. function Pg2_getTabLabel() {
  621.   return this.tabLabel;
  622. }
  623.  
  624. //Called to check if a page can be loaded
  625. //
  626. function Pg2_canLoad() {
  627.   with (this) {
  628.     handleSetObj.innerHTML = (GhandleMenu)?handleSetHTML:"";
  629.   }
  630.   return true;
  631. }
  632.  
  633. //Called when the layer for this page is displayed.
  634. // Use this call to initialize controls.
  635. //
  636. function Pg2_load() {
  637.   setOptions();
  638.   return true;
  639. }
  640.  
  641. //Called when one of the page controls calls the tabControl update function.
  642. // Use this call to respond to user input.
  643. //
  644. function Pg2_update(theItemName) {
  645.   var theObj, temp, temp2;
  646.  
  647.   theObj = findObject(theItemName);
  648.   with (this) {
  649.     if (theItemName == "handleMenu") {
  650.       myLayer.visibility = "hidden";  //workaround: hide layer before changing
  651.       handleSetObj.innerHTML = (theObj.selectedIndex)?handleSetHTML:"";
  652.       myLayer.visibility = "visible";
  653.     }
  654.   }
  655. }
  656.  
  657. //Called when another page is about to be shown, or finish() is called on
  658. // the tabControl.  Use this call to perform any finishing tasks.
  659. //
  660. function Pg2_unload() {
  661.   getOptions();
  662.   return true;
  663. }
  664.  
  665. //Called when finish() is called on the tabControl.
  666. // Use this call to perform any last minute page updates.
  667. //
  668. function Pg2_lastUnload() {
  669.   return true;
  670. }
  671.